<template>
  <div id="center">
    <div class="up">
      <div class="bg-color-black item" v-for="item in titleItem" :key="item.title">
        <p class="ml-3 colorBlue fw-b">{{item.title}}</p>
        <div>
          <dv-digital-flop :config="item.number" style="width:2.25rem;height:.625rem;" />
        </div>
      </div>
    </div>
    <div class="down">
      <div class="ranking bg-color-black">
        <span style="color:#5cd9e8">
          <icon name="align-left"></icon>
        </span>
        <span class="fs-xl text mx-2 mb-1">各州当日新增确诊人数</span>
        <dv-scroll-ranking-board :config="ranking" style="height:2.75rem" />
      </div>
      <div class="percent">
        <div class="item bg-color-black">
          <span>当日新增确诊率</span>
          <CenterChart :id="rate[0].id" :tips="rate[0].tips" :colorObj="rate[0].colorData" />
        </div>
        <div class="item bg-color-black">
          <span>当日新增死亡率</span>
          <CenterChart :id="rate[1].id" :tips="rate[1].tips" :colorObj="rate[1].colorData" />
        </div>
        <div class="water">
          <dv-water-level-pond :config="water" style="height: 1.5rem" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CenterChart from "@/components/echart/center/centerChartRate";

export default {
  data () {
    return {
      titleItem: [
        {
          title: "全年累计确诊人数",
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          }
        },
        {
          title: "本月累计确诊人数",
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          }
        },
        {
          title: "当日累计确诊人数",
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          }
        },
        {
          title: "全年累计死亡人数",
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          }
        },
        {
          title: "本月累计死亡人数",
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          }
        },
        {
          title: "当日累计死亡人数",
          number: {
            number: [0],
            toFixed: 0,
            content: "{nt}"
          }
        }
      ],
      ranking: {
        data: [],
        carousel: "single",
        unit: "人"
      },
      water: {
        data: [0],
        shape: "roundRect",
        formatter: "死亡率：{value}%",
        waveNum: 3
      },
      // 确诊率和死亡率的组件复用数据
      rate: [
        {
          id: "centerRate1",
          tips: 0,
          colorData: {
            textStyle: "#3fc0fb",
            series: {
              color: ["#00bcd44a", "transparent"],
              dataColor: {
                normal: "#03a9f4",
                shadowColor: "#97e2f5"
              }
            }
          }
        },
        {
          id: "centerRate2",
          tips: 0,
          colorData: {
            textStyle: "#67e0e3",
            series: {
              color: ["#faf3a378", "transparent"],
              dataColor: {
                normal: "#ff9800",
                shadowColor: "#fcebad"
              }
            }
          }
        }
      ]
    };
  },
  components: {
    CenterChart
    // centerChart1,
    // centerChart2
  },
  mounted() {
this.getdata();
  },
  methods: {
    async getdata(){
      let self = this;
      this.$http.get('http://116.196.92.193:8090/data/getCenter', {
        params: {
        }
      }).then(function (response) {
        //console.log(response);
        var n1 = response.data.data.daycase;
        var n2 = response.data.data.monthcase;
        var n3 = response.data.data.yearcase;
        var n4 = response.data.data.daydeath;
        var n5 = response.data.data.monthdeath;
        var n6 = response.data.data.yeardeath;

        var deathratio = response.data.data.deathratio;
        var addcaseratio = response.data.data.deathratio;
        var adddeathratio = response.data.data.adddeathratio;

        self.titleItem[0].number.number[0] = n3;
        self.titleItem[0].number = { ...self.titleItem[0].number };
        self.titleItem[1].number.number[0] = n2;
        self.titleItem[1].number = { ...self.titleItem[1].number };
        self.titleItem[2].number.number[0] = n1;
        self.titleItem[2].number = { ...self.titleItem[2].number };
        self.titleItem[3].number.number[0] = n6;
        self.titleItem[3].number = { ...self.titleItem[3].number };
        self.titleItem[4].number.number[0] = n5;
        self.titleItem[4].number = { ...self.titleItem[4].number };
        self.titleItem[5].number.number[0] = n4;
        self.titleItem[5].number = { ...self.titleItem[5].number };

        self.water.data.push(Math.round(deathratio*100));
        self.water = { ...self.water };

        self.rate[0].tips = Math.round(addcaseratio*100);

        self.rate[1].tips = Math.round(adddeathratio*100);

        var mapdata = response.data.data.map;
        //console.info(self.ranking.data);
        for(var k in mapdata){
          self.ranking.data.push({name:k,value:mapdata[k]});
        }
        self.ranking = { ...self.ranking };
      }).catch(function (error) {
        console.log(error);
      });
    },
  }
};
</script>

<style lang="scss" scoped>
#center {
  display: flex;
  flex-direction: column;
  .up {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    .item {
      border-radius: 0.0625rem;
      padding-top: 0.2rem;
      margin-top: 0.1rem;
      width: 32%;
      height: 0.875rem;
    }
  }
  .down {
    padding: 0.07rem 0.05rem;
    padding-bottom: 0;
    width: 100%;
    display: flex;
    height: 3.1875rem;
    justify-content: space-between;
    .bg-color-black {
      border-radius: 0.0625rem;
    }
    .ranking {
      padding: 0.125rem;
      width: 59%;
    }
    .percent {
      width: 40%;
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 50%;
        height: 1.5rem;
        span {
          margin-top: 0.0875rem;
          display: flex;
          justify-content: center;
        }
      }
      .water {
        width: 100%;
      }
    }
  }
}
</style>
